package cn.hanyx.coder.design.pattern.structural.bridge.demo02.handler;

import cn.hanyx.coder.design.pattern.structural.bridge.demo02.notify.Notification02;
import cn.hanyx.coder.design.pattern.structural.bridge.info.AlertRule;
import cn.hanyx.coder.design.pattern.structural.bridge.info.ApiStatInfo;

/**
 * TimeoutTpsAlerthandler
 *
 * @author hanyx
 * @date 2020/05/19
 */
public class TimeoutTpsAlerthandler extends AlertHandler {

    public TimeoutTpsAlerthandler(AlertRule rule, Notification02 notification) {
        super(rule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        long timeoutTps = apiStatInfo.getTimeoutCount() / apiStatInfo.getDurationOfSeconds();
        if (timeoutTps > rule.getMatchedRule(apiStatInfo.getApi()).getMaxTimeoutTps()) {
            notification.notify(apiStatInfo.getApi());
        }
    }
}
